package com.example.webfluxtest.config;

import com.example.webfluxtest.handler.MyHandlerFilterFunction;
import com.example.webfluxtest.handler.PlayerHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;

/**
 * @description: WebFluxConfig
 * @author: Zhengwen li
 * @date: 2022-12-08
 * @version:1.0
 **/
@Configuration
public class WebFluxConfig {
    @Bean
    public RouterFunction<ServerResponse> route(PlayerHandler playerHandler) {
        return RouterFunctions
                .route(GET("/players/{name}"), playerHandler::getName)
                .filter(new MyHandlerFilterFunction());
    }

    @Bean
    public RouterFunction<ServerResponse> route1(PlayerHandler playerHandler) {
        return RouterFunctions
                .route(GET("/players1/{name}"), playerHandler::getName)
                .filter(new MyHandlerFilterFunction());
    }
}

